package com.yygo.jobs;

import com.yygo.model.LoanRequest;
import com.yygo.model.Rule;
import com.yygo.model.enums.RequestStatus;
import com.yygo.service.LoanRequestManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by tiansha on 2015/7/4.
 */
@Component("D401")
public class D401 extends BaseRuleProcessor implements RuleProcessor {

    @Autowired
    private LoanRequestManager loanRequestManager;

    @Override
    public Rule process(LoanRequest loanRequest) {
        boolean flag = false;
        List<LoanRequest> list = getHistoryRequests(loanRequest);
        for (LoanRequest request : list) {
            RequestStatus status = request.getStatus();
            if (RequestStatus.dealer_apply_loan.equals(status)
                    || RequestStatus.loan_approved.equals(status) || RequestStatus.loan_audit.equals(status)) {
                flag = true;
                break;
            }
        }
        if (flag) {
            Rule rule = new Rule("D401", "请确认客户是否二次购车，注意首付比例");
            rule.setUrl("history");
            List<String> numbers = getNumbers(list);
            rule.getNumbers().addAll(numbers);
            return rule;
        }
        return null;
    }

}